package com.top.vueservice.service.mongo.impl;

import com.top.vueservice.dao.mongo.MyUserRepository;
import com.top.vueservice.entities.mongo.MyUser;
import com.top.vueservice.service.mongo.MyUserService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@Service
public class MyUserServiceImpl implements MyUserService {
    @Resource
    private MyUserRepository myUserRepository;

    @Override
    public Page<MyUser> findByStrName(String strName, int page, int pageSize) {
        return myUserRepository.findByStrName(strName, PageRequest.of(page-1,pageSize));

    }

    @Override
    public Optional<MyUser> findById(String id) {
        return myUserRepository.findById(id);
    }

    @Override
    public List<MyUser> findAll() {
        List<MyUser> all = myUserRepository.findAll();
        return all;
    }

    @Override
    public MyUser findByName(String strName) {
        return myUserRepository.findMyUserByStrName(strName);
    }

    @Override
    public void insertUser(MyUser myUser) {
        myUserRepository.insert(myUser);
    }


}
